﻿#pragma once
#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<assert.h>
using namespace std;

class MyString
{
public:
	typedef char* iterator;
	typedef const char* const_iterator;

	iterator begin();
	iterator end();

	const_iterator begin() const;
	const_iterator end() const;

	//MyString();
	MyString(const char* str = "");
	MyString(const MyString& s);
	MyString& operator=(const MyString& s);
	~MyString();

	const char* c_str() const;

	size_t size() const;
	size_t capacity() const;
	char& operator[](size_t pos);
	const char& operator[](size_t pos) const;

	void reserve(size_t n);

	void push_back(char ch);
	void append(const char* str);

	MyString& operator+=(char ch);
	MyString& operator+=(const char* str);

	void insert(size_t pos, char ch);
	void insert(size_t pos, const char* str);
	void erase(size_t pos = 0, size_t len = npos);

	size_t find(char ch, size_t pos = 0);
	size_t find(const char* str, size_t pos = 0);

	void swap(MyString& s);
	MyString substr(size_t pos = 0, size_t len = npos);

	bool operator<(const MyString& s) const;
	bool operator>(const MyString& s) const;
	bool operator<=(const MyString& s) const;
	bool operator>=(const MyString& s) const;
	bool operator==(const MyString& s) const;
	bool operator!=(const MyString& s) const;
	void clear();
private:
	char* _str;
	size_t _size;
	size_t _capacity;
	const static size_t npos;
};

istream& operator>> (istream& is, MyString& str);
ostream& operator<< (ostream& os, const MyString& str);